﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using DailyDiet.Models;
using DailyDiet.Services;
using DailyDiet.Services.Impl;

namespace DailyDiet.util
{
    /*
     * 用来给记录填数据的
     */
    public class RecorderStorageFillMeassage : IRecorderStorageFillMeassage
    {
        private int[] list1 = new[] {1, 2, 3};
        private int[] list2 = new[] {11, 21, 13};
        private int[] list3 = new[] {12, 22, 23};
        private int[] list4 = new[] {13, 23, 13};
        private int[] list5 = new[] {15, 25, 3};
        private int[] list6 = new[] {18, 21, 32};
        private IDietRecorderStorageService _dietRecorderStorageService;

        private List<int[]> list = new List<int[]>();

        public async Task initial() {
            list.Add(list2);
            list.Add(list3);
            list.Add(list4);
            list.Add(list5);
            list.Add(list6);

            DateTime now = DateTime.Now;

            for (int i = 1; i < now.Day; i++) {
                int index = i % 5;
                int[] list_ = list[index];
                DateTime date = new DateTime(now.Year, now.Month, i);
                List<DietRecorder> breakfastRecorders =
                    new List<DietRecorder>();
                foreach (var id in list1)
                {
                    breakfastRecorders.Add(new DietRecorder() { DietId = id, Date = date.ToString("yyyy-MM-dd"), MealTimes = DietRecorderConstant.Breakfast });
                }

                List<DietRecorder> recorders = new List<DietRecorder>();
                foreach (var id in list_) {
                    recorders.Add(new DietRecorder(){DietId = id,Date = date.ToString("yyyy-MM-dd"),MealTimes = DietRecorderConstant.Dinner});
                }

                await _dietRecorderStorageService.InsertAll(breakfastRecorders);
                await _dietRecorderStorageService.InsertAll(recorders);
            }
        }

        public RecorderStorageFillMeassage(IDietRecorderStorageService dietRecorderStorageService) {
            _dietRecorderStorageService = dietRecorderStorageService;
        }
    }
}
